import { db_config } from "../config";
import { DataSource, EntityManager } from "typeorm";
import { User } from './models/user';


const db_client = new DataSource({
	type: 'mysql',
	host: db_config.host,
	port: db_config.port,
	username: db_config.username,
	password: db_config.password,
	database: db_config.database,
	synchronize: false,
	logging: true,
	entities: ['src/database/models/**/*.ts'],
	subscribers: [],
	migrations: []
})

db_client.initialize()
.then(() => console.log('Database connected...'))
.catch(err => console.log(err))

export const db: EntityManager = db_client.manager

export const userMapper = db_client.getRepository(User)

export default db

